﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using Web.UI;

namespace Web.frontpage.SignUp.right
{
    public partial class UpPassword : SignUpPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["studentName"] == null)
            {
                Response.Write("<script>alert('对不起，你没有登录');parent.location.href='../login.aspx';</script>");
            }
        }
        /// <summary>
        /// 提交按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void SubmitClick(object sender, EventArgs e)
        {
            string oldpwd = oldPwd.Value;
            string newpwd1 = newPwd1.Value;
            string newpwd2 = newPwd2.Value;
            if (string.IsNullOrEmpty(oldpwd) || string.IsNullOrEmpty(newpwd1) || string.IsNullOrEmpty(newpwd2))
            {
                Response.Write("<script>alert('不允许有空项！！')</script>");
            }
            else if (newpwd1 != newpwd2)
            {
                Response.Write("<script>alert('两次密码输入不一致！！')</script>");
            }
            else
            {
                BLL.StudentService studensService = new BLL.StudentService();
                BoStudents model = studensService.getStudent(Session["studentId"].ToString());
                model.STU_PASSWORD = oldpwd;
                BoStudents resultModel = studensService.CheckStudent(model);
                if (resultModel != null)
                {
                    resultModel.STU_PASSWORD = newpwd1;
                    studensService.UpdateStudent(resultModel);
                    Response.Write("<script>alert('修改密码成功！！')</script>");
                }
                else
                    Response.Write("<script>alert('原密码错误！！')</script>");
            }
        }
    }
}